package Jcat.cduestcbbs.tools;

import java.util.HashSet;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;

public class OnlineNumber {
	static Set<Object> userThreadSet = new HashSet<Object>();
	static int guestNumber;
	static int memberNumber;

	public static synchronized void addOneGuest(HttpServletRequest req) {
		if (userThreadSet.add(req.getSession())) {
			System.out.print(req.getSession());
			guestNumber += 1;
		}

	}

	public static synchronized void addOneMenber() {

		if (userThreadSet.add(Thread.currentThread())) {
			memberNumber += 1;
			guestNumber -= 1;
		} else {

			memberNumber += 1;
		}

	}

	public static synchronized int getGuestNumber() {
		return guestNumber;
	}

	public static synchronized int getMemberNumber() {
		return memberNumber;
	}
}
